/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.reddys.rad.inventory.helper;

import com.reddys.rad.inventory.db.PurchaseOrder;
import com.reddys.rad.inventory.db.PurchaseOrderDetails;
import com.reddys.rad.inventory.utils.Utilities;
import java.util.ArrayList;
import javafx.collections.ObservableList;
import javafx.scene.control.TableView;

/**
 *
 * @author REDDYS
 */
public class PurchaseOrderHelper {
    
    public static ArrayList getPurchaseOrderDetails(TableView tableView,PurchaseOrder purchaseOrder){
     ArrayList purchaseOrderList = new ArrayList();
      for(int i =0;i<tableView.getItems().size();i++){
        ObservableList purchaseOrderDetails = (ObservableList) tableView.getItems().get(i);
        if(!Utilities.isNull(purchaseOrder.getPurchaseOrderId()) && !Utilities.isNull(purchaseOrderDetails.get(1).toString())){
           PurchaseOrderDetails purchasseOrderDetail = new PurchaseOrderDetails();
            System.out.println(purchaseOrder.getPurchaseOrderId());
            purchasseOrderDetail.setPurchaseOrderId(purchaseOrder.getPurchaseOrderId());
            purchasseOrderDetail.setPurchaseOrderDate(Utilities.getCurrentDate());
            purchasseOrderDetail.setProductId(purchaseOrderDetails.get(1)!=null?purchaseOrderDetails.get(1).toString():"");
            purchasseOrderDetail.setProductName(purchaseOrderDetails.get(2)!=null?purchaseOrderDetails.get(2).toString():"");
            purchasseOrderDetail.setQuantity(purchaseOrderDetails.get(4)!=null?Double.valueOf(purchaseOrderDetails.get(4).toString()):new Double(0.0));
            purchasseOrderDetail.setUom(purchaseOrderDetails.get(7)!=null&&!purchaseOrderDetails.get(7).toString().isEmpty()?purchaseOrderDetails.get(7).toString():"");
            purchasseOrderDetail.setUnitPrice(purchaseOrderDetails.get(8)!=null&&!purchaseOrderDetails.get(8).toString().isEmpty()?Double.valueOf(purchaseOrderDetails.get(8).toString()):new Double(0.0));
            purchasseOrderDetail.setQuantityOrdered(purchaseOrderDetails.get(4)!=null?Double.valueOf(purchaseOrderDetails.get(4).toString()):new Double(0.0));
            purchasseOrderDetail.setQuantityReceived(new Double(0.0));
            purchasseOrderDetail.setQuantityRemaining(purchaseOrderDetails.get(4)!=null?Double.valueOf(purchaseOrderDetails.get(4).toString()):new Double(0.0));
            purchaseOrderList.add(purchasseOrderDetail);
        }
    }  
    return purchaseOrderList;
    }
}
